import os
from os import path

from werkzeug.datastructures import FileStorage

basepath = path.join(path.dirname(path.abspath(__file__)), r'..\..', r'static\uploads')


def delete_file(name: str):
    if path.exists(path.join(basepath, name)):
        os.remove(path.join(basepath, name))


def save_file(f: FileStorage, fid: str):
    file_path = path.join(basepath, fid)
    if not path.exists(basepath):
        os.mkdir(basepath)
    f.save(file_path)
